﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Configuration;
using System.IO;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using System.Web.Security;
using System.Data;

namespace StockShark.Models
{
    public class SSInitializer : DropCreateDatabaseIfModelChanges<StockSharkDB>
    {
        // nalezy zmienic na odpowiednia sciezke
        private string scriptDirectory = "C:\\Users\\Mith\\Documents\\Studia\\S8\\ZIWG\\Projekt\\Skrypty\\";
        //private string scriptDirectory = "E:\\Semestr_1_mgr\\Zastosowania_informatyki_w_gospodarce\\Projekt\\Skrypty\\";
        private string sqlConnectionString;
        private SqlConnection connection;
        private Server server;

        protected override void Seed(StockSharkDB context)
        {
            base.Seed(context);

            sqlConnectionString = ConfigurationManager.ConnectionStrings["StockSharkDB"].ConnectionString;
            connection = new SqlConnection(sqlConnectionString);
            server = new Server(new ServerConnection(connection));

            RunScripts(scriptDirectory);
            RegisterTestUsers(5);
            InsertSampleData(context);
        }

        private void RunScripts(string scriptDir)
        {
            string sqlConnectionString = ConfigurationManager.ConnectionStrings["StockSharkDB"].ConnectionString;
            List<FileInfo> scriptFiles = new List<FileInfo>();
            scriptFiles.Add(new FileInfo(scriptDir + "InstallCommon.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "InstallMembership.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "InstallRoles.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "Patch.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "Dictionary.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "FillShare.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "FillCurrency.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "FillIndex.sql"));
            scriptFiles.Add(new FileInfo(scriptDir + "FillMaterial.sql"));

            foreach (FileInfo sf in scriptFiles)
            {
                FileInfo fileInfo = new FileInfo(sf.FullName);
                string script = fileInfo.OpenText().ReadToEnd();
                server.ConnectionContext.ExecuteNonQuery(script);
            }
        }

        private void RegisterTestUsers(int number)
        {
            for (int i = 1; i <= number; i++)
                Membership.CreateUser("user" + i, "password" + i);
        }

        private void InsertSampleData(StockSharkDB context)
        {
            SqlDataReader reader;
            reader = server.ConnectionContext.ExecuteReader("SELECT UserId, UserName FROM StockSharkDB.dbo.aspnet_Users;");
            BrokerageAccount konto = new BrokerageAccount();

            // rachunki maklerskie
            while (reader.Read())
            {
                if (((string)reader.GetValue(1)).Equals("user1"))
                {
                    context.BrokerageAccounts.Add(konto = new BrokerageAccount 
                    { 
                        UserId = (Guid)reader.GetValue(0), 
                        Name = "konto1", 
                        Balance = 40000.00M,
                        TotalValue = 55000.00M,
                        CreationDate = new DateTime(2012, 4, 2)
                    });
                    context.BrokerageAccounts.Add(new BrokerageAccount 
                    { 
                        UserId = (Guid)reader.GetValue(0), 
                        Name = "konto2", 
                        Balance = 50000.00M,
                        TotalValue = 50000.00M,
                        CreationDate = new DateTime(2012, 4, 2)
                    });
                    context.BrokerageAccounts.Add(new BrokerageAccount 
                    { 
                        UserId = (Guid)reader.GetValue(0), 
                        Name = "konto3", 
                        Balance = 50000.00M,
                        TotalValue = 50000.00M,
                        CreationDate = new DateTime(2012, 4, 2)
                    });
                }
                else if (((string)reader.GetValue(1)).Equals("user2"))
                {
                }
                else
                {
                    context.BrokerageAccounts.Add(new BrokerageAccount 
                    { 
                        UserId = (Guid)reader.GetValue(0), 
                        Name = "konto", 
                        Balance = 50000.00M,
                        TotalValue = 50000.00M,
                        CreationDate = new DateTime(2012, 4, 2)
                    });
                }
            }

            // indeksy gieldowe
            //List<Index> indexes = new List<Index>
            //{
            //    new Index 
            //    { 
            //        Name = "Indeks1", 
            //        Acronym = "Idx1", 
            //        CurrentPrice = 200.00M, 
            //        ReferencePrice = 202.00M,
            //        Description = "Opis...",                    
            //        WebLink = "http://onet.pl",
            //        Market = "GPW Rynek Główny",
            //    },
            //    new Index 
            //    { 
            //        Name = "Indeks2", 
            //        Acronym = "Idx2", 
            //        CurrentPrice = 300.00M,
            //        ReferencePrice = 298.00M,
            //        Description = "Opis...", 
            //        WebLink = "http://onet.pl",
            //        Market = "NewConnect",
            //    }                
            //};
            //indexes.ForEach(s => context.Indexes.Add(s));

            // akcje
            //List<Share> shares = new List<Share>
            //{
            //    new Share 
            //    { 
            //        Name = "Spolka1", 
            //        Acronym = "Sp1", 
            //        CurrentPrice = 20.00M,
            //        ReferencePrice = 20.00M,
            //        Description = "Opis...",
            //        Sector = "Jakis sektor",
            //        WebLink = "http://onet.pl", 
            //        Market = "GPW Rynek Główny", 
            //        Fixing = false 
            //    },
            //    new Share 
            //    { 
            //        Name = "Spolka2", 
            //        Acronym = "Sp2", 
            //        CurrentPrice = 30.00M,
            //        ReferencePrice = 29.00M,
            //        Description = "Opis...", 
            //        Sector = "Jakis sektor",
            //        WebLink = "http://onet.pl", 
            //        Market = "GPW Rynek Główny",
            //        Fixing = false },
            //    new Share 
            //    { 
            //        Name = "Spolka3", 
            //        Acronym = "Sp3", 
            //        CurrentPrice = 40.00M, 
            //        ReferencePrice = 50.00M,
            //        Description = "Opis...",
            //        Sector = "Jakis sektor",
            //        WebLink = "http://onet.pl", 
            //        Market = "GPW Rynek Główny",
            //        Fixing = true 
            //    },
            //    new Share 
            //    { 
            //        Name = "Spolka4", 
            //        Acronym = "Sp4", 
            //        CurrentPrice = 0.00M, 
            //        ReferencePrice = 40.00M,
            //        Description = "Opis...", 
            //        Sector = "Jakis sektor",
            //        WebLink = "http://onet.pl", 
            //        Market = "NewConnect", 
            //        Fixing = false },
            //    new Share 
            //    { 
            //        Name = "Spolka5", 
            //        Acronym = "Sp5", 
            //        CurrentPrice = 60.00M,
            //        ReferencePrice = 62.00M,
            //        Description = "Opis...",
            //        Sector = "Jakis sektor",
            //        WebLink = "http://onet.pl", 
            //        Market = "NewConnect", 
            //        Fixing = false 
            //    },
            //    new Share 
            //    { 
            //        Name = "Spolka6", 
            //        Acronym = "Sp6", 
            //        Sector = "Jakis sektor",
            //        CurrentPrice = 10.00M, 
            //        ReferencePrice = 8.00M,
            //        Market = "GPW Rynek Główny",
            //        Fixing = false 
            //    }
            //};
            //shares.ForEach(s => context.Shares.Add(s));

            // waluty
            //List<Currency> currencies = new List<Currency>
            //{
            //    new Currency 
            //    { 
            //        Name = "USD/PLN", 
            //        Acronym = "USD/PLN", 
            //        CurrentPrice = 3.19M,
            //        ReferencePrice = 3.19M,
            //        Description = "Opis...", 
            //        WebLink = "http://onet.pl", 
            //        Market = "Forex",
            //    },
            //    new Currency 
            //    { 
            //        Name = "EUR/PLN", 
            //        Acronym = "EUR/PLN", 
            //        CurrentPrice = 4.17M,
            //        ReferencePrice = 4.15M,
            //        Description = "Opis...", 
            //        WebLink = "http://onet.pl", 
            //        Market = "Forex",
            //    },
            //    new Currency 
            //    { 
            //        Name = "CHF/PLN", 
            //        Acronym = "CHF/PLN", 
            //        CurrentPrice = 3.47M,
            //        ReferencePrice = 3.50M,
            //        Market = "Forex",
            //    },
            //};
            //currencies.ForEach(s => context.Currencies.Add(s));

            // surowce
            //List<Material> materials = new List<Material>
            //{
            //    new Material 
            //    { 
            //        Name = "ZŁOTO", 
            //        Acronym = "ZŁOTO", 
            //        CurrentPrice = 1674.40M,
            //        ReferencePrice = 1675.00M,
            //        Description = "Opis...", 
            //        WebLink = "http://onet.pl", 
            //        Market = "Nymex",
            //    },
            //    new Material 
            //    { 
            //        Name = "SREBRO", 
            //        Acronym = "SREBRO", 
            //        CurrentPrice = 32.34M,
            //        ReferencePrice = 33.00M,
            //        Description = "Opis...", 
            //        WebLink = "http://onet.pl", 
            //        Market = "GTF Global Markets",
            //    },
            //};
            //materials.ForEach(s => context.Materials.Add(s));

            // historia wartosci rachunku
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 2, 00, 00, 00),
                Value = 50000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 3, 00, 00, 00),
                Value = 53000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 4, 00, 00, 00),
                Value = 52000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 5, 00, 00, 00),
                Value = 54000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 6, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 7, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 8, 00, 00, 00),
                Value = 56000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 9, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 10, 00, 00, 00),
                Value = 57000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 11, 00, 00, 00),
                Value = 56000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 12, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 13, 00, 00, 00),
                Value = 54000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 14, 00, 00, 00),
                Value = 53000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 15, 00, 00, 00),
                Value = 52000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 16, 00, 00, 00),
                Value = 54000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 17, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 18, 00, 00, 00),
                Value = 56000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 19, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 20, 00, 00, 00),
                Value = 54000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 21, 00, 00, 00),
                Value = 53000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 22, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 23, 00, 00, 00),
                Value = 52000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 24, 00, 00, 00),
                Value = 53000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 25, 00, 00, 00),
                Value = 54000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 26, 00, 00, 00),
                Value = 55000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 27, 00, 00, 00),
                Value = 57000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 28, 00, 00, 00),
                Value = 58000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 29, 00, 00, 00),
                Value = 57000.00M
            });
            context.AccountValues.Add(new AccountValue
            {
                BrokerageAccount = konto,
                Timestamp = new DateTime(2012, 4, 30, 00, 00, 00),
                Value = 54000.00M
            });


            Share share1 = context.Shares.Single(r => r.Name.Equals("ABCDATA"));
            share1.ReferencePrice = 2.00M;
            share1.CurrentPrice = 2.00M;
            Share share2 = context.Shares.Single(r => r.Name.Equals("BIOTON"));
            share2.ReferencePrice = 0.10M;
            share2.CurrentPrice = 0.10M;
            Share share3 = context.Shares.Single(r => r.Name.Equals("11BIT"));
            share3.ReferencePrice = 10.00M;
            share3.CurrentPrice = 11.00M;
            Currency curr1 = context.Currencies.Single(r => r.Name.Equals("EUR/PLN"));
            curr1.ReferencePrice = 4.10M;
            curr1.CurrentPrice = 4.00M;
            Material mat1 = context.Materials.Single(r => r.Name.Equals("PLATYNA"));
            mat1.ReferencePrice = 420.00M;
            mat1.CurrentPrice = 4800.00M;
            Index ind1 = context.Indexes.Single(r => r.Name.Equals("WIG20"));
            ind1.ReferencePrice = 2300.00M;
            ind1.CurrentPrice = 2350.00M;

            // posiadane walory na rachunku
            context.OwnedInstruments.Add(new OwnedInstrument 
            { 
                BrokerageAccount = konto, 
                Paper = share1,
                Quantity = 100 
            });
            context.OwnedInstruments.Add(new OwnedInstrument 
            { 
                BrokerageAccount = konto, 
                Paper = share2,
                Quantity = 1000
            });
            context.OwnedInstruments.Add(new OwnedInstrument 
            { 
                BrokerageAccount = konto, 
                Paper = share3, 
                Quantity = 20 
            });
            context.OwnedInstruments.Add(new OwnedInstrument 
            { 
                BrokerageAccount = konto, 
                Paper = curr1,
                Quantity = 500 
            });
            context.OwnedInstruments.Add(new OwnedInstrument
            {
                BrokerageAccount = konto,
                Paper = mat1,
                Quantity = 5
            });

            // historia transakcji na rachunku
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = share1,
                Quantity = 200,
                UnitPrice = 2.00M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 2, 12, 30, 00)
            });
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = share2,
                Quantity = 1000,
                UnitPrice = 0.10M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 2, 13, 30, 00)
            });
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = share3,
                Quantity = 20,
                UnitPrice = 10.00M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 2, 14, 30, 00)
            });
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = curr1,
                Quantity = 500,
                UnitPrice = 4.00M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 4, 12, 30, 00)
            });
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = mat1,
                Quantity = 15,
                UnitPrice = 4800.00M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 4, 11, 30, 00)
            });
            context.ExecutedTransaction.Add(new ExecutedTransaction
            {
                BrokerageAccount = konto,
                BuyNotSell = false,
                Paper = share1,
                Quantity = 100,
                UnitPrice = 2.00M,
                Commission = 3.00M,
                ExecutionDate = new DateTime(2012, 4, 5, 11, 30, 00)
            });

            // oczekujace zlecenia na rachunku
            context.Orders.Add(new Order
            {
                BrokerageAccount = konto,
                BuyNotSell = true,
                Paper = share3,
                IssuingDate = new DateTime(2012, 4, 6, 10, 30, 00),
                Deadline = new DateTime(2012, 6, 13, 10, 30, 00),
                Quantity = 20,
                AllowPartial = true,
                PriceLimit = 8.00M
            });

            // notowania 
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 2, 00, 00, 00),
                Value = 2.40M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 3, 00, 00, 00),
                Value = 2.50M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 4, 00, 00, 00),
                Value = 2.60M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 5, 00, 00, 00),
                Value = 2.40M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 6, 00, 00, 00),
                Value = 2.20M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 9, 00, 00, 00),
                Value = 2.10M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 10, 00, 00, 00),
                Value = 1.90M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 11, 00, 00, 00),
                Value = 2.00M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 12, 00, 00, 00),
                Value = 2.00M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 13, 00, 00, 00),
                Value = 2.20M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 16, 00, 00, 00),
                Value = 2.10M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 17, 00, 00, 00),
                Value = 2.20M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 18, 00, 00, 00),
                Value = 2.30M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 19, 00, 00, 00),
                Value = 2.20M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 20, 00, 00, 00),
                Value = 2.30M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 21, 00, 00, 00),
                Value = 2.20M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 22, 00, 00, 00),
                Value = 2.30M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 23, 00, 00, 00),
                Value = 2.50M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 24, 00, 00, 00),
                Value = 2.50M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 25, 00, 00, 00),
                Value = 2.60M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 26, 00, 00, 00),
                Value = 2.40M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 27, 00, 00, 00),
                Value = 2.30M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 28, 00, 00, 00),
                Value = 2.30M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 29, 00, 00, 00),
                Value = 2.40M
            });
            context.Quotations.Add(new Quotation
            {
                Paper = share1,
                Timestamp = new DateTime(2012, 4, 30, 00, 00, 00),
                Value = 2.30M
            });

            // obserwowane
            context.WatchedInstruments.Add(new WatchedInstrument
            {
                UserId = konto.UserId,
                Paper = share1
            });
            context.WatchedInstruments.Add(new WatchedInstrument
            {
                UserId = konto.UserId,
                Paper = share2
            });
            context.WatchedInstruments.Add(new WatchedInstrument
            {
                UserId = konto.UserId,
                Paper = curr1
            });
            context.WatchedInstruments.Add(new WatchedInstrument
            {
                UserId = konto.UserId,
                Paper = mat1
            });
            context.WatchedInstruments.Add(new WatchedInstrument
            {
                UserId = konto.UserId,
                Paper = ind1
            });

                
        }
    }
}